package org.osgifx;

import javafx.async.RunnableFuture;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;

/**
 *
 * @author johan
 */
public class NativeInstaller implements RunnableFuture {
  private final String location;
  private final BundleContext bc;

  public NativeInstaller (BundleContext bc, String loc) {
    this.bc = bc;
    this.location = loc;
  }

  @Override
  public void run() throws Exception {
    try {
     // com.sun.javafx.runtime.FXObject foo = new com.sun.javafx.runtime.FXObject();
    System.out.println ("[JVDBG] I have to install bundle at "+location);
    Bundle bundle = bc.installBundle(location);
        System.out.println ("[JVDBG] bundlestate is before " + bundle.getState());

    System.out.println ("[JVDBG] I installed "+location);
    bundle.start();
    System.out.println ("[JVDBG] headers: "+bundle.getHeaders());
        System.out.println ("[JVDBG] bundlestate is " + bundle.getState());

    System.out.println ("[JVDBG] I started "+location);
    System.out.println ("[JVDBG] bundlestate is now " + bundle.getState());
    }

    catch (Exception e) {
      e.printStackTrace();
    }
  }

}
